function [output]=segmentation(Inputimage,SkinIndexRow,SkinIndexCol)
Inputimage=double(Inputimage);
H=size(Inputimage,1);
W=size(Inputimage,2);
S=zeros(H,W);

YCbCr=rgb2ycbcr(Inputimage);
Cr=YCbCr(:,:,3);
S=zeros(H,W);
[SkinIndexRow,SkinIndexCol] =find(10<Cr & Cr<45);

%creating mask
for i=1:length(SkinIndexRow)
    S(SkinIndexRow(i),SkinIndexCol(i))=1;
end

%noise removal
SN=zeros(H,W);
for i=1:H-5
    for j=1:W-5
        localSum=sum(sum(S(i:i+4, j:j+4)));
        SN(i:i+5, j:j+5)=(localSum>12);
    end
end


%ANDing the mask and obtain segmented image
r=Inputimage(:,:,1);
 g=Inputimage(:,:,2);
 b=Inputimage(:,:,3);
 r=double(r);
 g=double(g);
 b=double(b);
 r=S.*r;
 g=S.*g;
 b=S.*b;
 r=uint8(r);
 g=uint8(g);
 b=uint8(b);
 output(:,:,1)=r;
 output(:,:,2)=g;
 output(:,:,3)=b;


%figure,imshow(output);
%title('skin')